package edu.fmi.st.epf.types.skill.common.handler;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.epf.uma.CustomCategory;

import edu.fmi.st.epf.types.skill.common.util.SkillHelper;
import eu.tanov.epf.pv.service.types.handler.CustomTypeHandler;
import eu.tanov.epf.pv.service.types.util.CustomTypeHelper;

public class SkillCustomTypeHandler implements
		CustomTypeHandler<CustomCategory> {

	/**
	 * XXX if used outside - move to ProjectPracticeHelper
	 */
	public static final String TYPE_NAME = "Skill";

	private final EClass skillEClass;

	public SkillCustomTypeHandler() {
		this.skillEClass = CustomTypeHelper.createType(TYPE_NAME);
	}

	/*
	 * based on http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/
	 */
	public void registerType() {
		CustomTypeHelper.getExtendedUmaPackage().getEClassifiers()
				.add(skillEClass);
	}

	public EObject wrap(EObject object) {
		return CustomTypeHelper.copy(object, skillEClass);
	}

	public boolean matches(EObject object) {
		return SkillHelper.isSkill(object);
	}

	public EClass getCustomType() {
		return skillEClass;
	}

	public Class<CustomCategory> getHolderType() {
		return CustomCategory.class;
	}

	public String[] getCategoryPkgPath() {
		return SkillHelper.SKILLS_PATH;
	}

	public boolean isReadyToRegisterType() {
		// depends on technique
		return true;
	}

}
